﻿using MaxLeaf.Platform.BLLProxy;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using MaxLeaf.Platform.DataContract;
using System.Collections.Generic;
using MaxLeaf.Platform.BLLImplementation;
using CommonsLib.DB;
using MaxLeaf.Platform.Functions;

namespace BLLUnitTest
{
    
    
    /// <summary>
    ///这是 imUsingListProcessorProxyTest 的测试类，旨在
    ///包含所有 imUsingListProcessorProxyTest 单元测试
    ///</summary>
    [TestClass()]
    public class imUsingListProcessorProxyTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Post 的测试
        ///</summary>
        [TestMethod()]
        public void PostTest()
        {
           
                using (DBAccess dbcon = new DBAccess(DataFunc.GetConnectionInfo("DB_A")))
                {
                    using (System.Transactions.TransactionScope ts = DataFunc.CreateTransactionScope())
                    {
                        string strsql = string.Format("insert into a(name) values('{0}')", DateTime.Now);
                        dbcon.ExecuteSql(strsql);
                        B();

                        throw new Exception("Error A");
                        ts.Complete();
                    }

                }


            ////imUsingListProcessorProxy target = new imUsingListProcessorProxy(); // TODO: 初始化为适当的值
            ////List<int> lstUsingListKeys = new List<int> { 5,6}; // TODO: 初始化为适当的值
          
            ////imStoresReqHdrDataModel actual;
            ////actual = target.Post(1,0,lstUsingListKeys);
            ////Assert.IsNotNull(actual);
            ////Assert.AreNotEqual<int>(actual.Key,0);
            ////Assert.AreNotEqual<string>(actual.OrdNo,string.Empty);
        }

        private void B()
        {
            using (System.Transactions.TransactionScope ts = DataFunc.CreateTransactionScope( System.Transactions.TransactionScopeOption.Suppress))
            {

                using (DBAccess dbcon = new DBAccess(DataFunc.GetConnectionInfo("DB_B")))
                {

                    string strsql = string.Format("insert into a(name) values('{0}')", DateTime.Now);
                    dbcon.ExecuteSql(strsql);

                    //throw new Exception("ex");
                }

                ////ts.Complete();
            }
             
        }

         
    }
}
